home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: news.sprintlink.net!eskimo!scs
- From: scs@eskimo.com (Steve Summit)
- Subject: Re: void main() and other atrocities!
- X-Nntp-Posting-Host: eskimo.com
- Message-ID: <DMHCyB.C7y@eskimo.com>
- Sender: news@eskimo.com (News User Id)
- Organization: schmorganization
- References: <4erjn2INN38b@keats.ugrad.cs.ubc.ca> <9602021300.AA04359@dxmint.cern.ch> <4f2rahINNmud@keats.ugrad.cs.ubc.ca>
- Date: Thu, 8 Feb 1996 23:22:58 GMT
-
- In article <4f2rahINNmud@keats.ugrad.cs.ubc.ca>, c2a192@ugrad.cs.ubc.ca
- (Kazimir Kylheku) writes:
- > I know that it would break a compiler that generates an incompatible
- > linkage for functions returning int and void functions (assuming that
- > the function you are calling does not return). But I just don't know
- > of any that do (and it would be silly to write one that generates
- > subroutine linkage code which breaks when a void function is called
- > that is assumed to be int).
-
- Why would it be silly? The only reason for going out of your way
- to make void- and int-valued functions compatible would be to
- coddle the large body of existing C code that mistakenly assumes
- that they are. (This is, to be sure, a big reason.) If, on the
- other hand, you could get away with making void- and int-valued
- functions incompatible, you could, for example, make it easier to
- mix C functions with Pascal procedures and functions, without
- requiring klunky nonstandard "pascal" keywords. (This issue is
- of more than academic interest when you're doing any Macintosh
- programming.)
-
- > It's also atrocious that main() has to be treated as a special
- > language construct,
-
- But it doesn't. Many compilers do special-case main(), and it's
- not out of the question since it's such a distinguished function,
- but the only way the C Standard might force a compiler to special-
- case main() is that it has two acceptable prototypes (which is a
- terrible anomaly).
-
- > and that a call to exit() in main() (when it is
- > the last statement) is to be identical to a return.
-
- Huh? What's so atrocious about that? (And why are you arguing
- so strongly for atrocity here, when you're so moderate in your
- next sentence about how serious a mistake void main() is?)
-
- > I don't advocate that people declare main() to return void (in fact I
- > don't do so myself),
-
- Good! But why condone or make excuses for the practice?
-
- In fact, let me ask this: to anyone who vociferously argues that
- there's nothing wrong with void() main, what's right with it?
- What's so wrong with int main() that you refuse to use it?
- Why are you so determined to use void main()?
-
- > but I don't see it as some sort of big mistake.
-
- It's true that people on comp.lang.c tend to make an overly big
- deal out of it. It's true that it's likely to work in a large
- number of situations. But it's also true that there's no good
- reason for using it (well, I take that back, I guess it's only my
- opinion that there's no good reason for using it), so I don't
- understand why the argument persists.
-
- > I did read the relevant section in the FAQ. It is merely concerned
- > with the issue of eliminating compiler warnings stemming from calling
- > exit() in main() despite a "void" declaration thereof.
-
- Well, that's what the question was originally concerned with,
- anyway; back when I composed that entry, void main() was rare and
- was done for a deliberate reason (to eliminate warnings when
- main() called exit() and did not explicitly return). But now --
- as proliferating numbers of programmers seem to be using the
- silly little construct, not knowing why, but merely basing their
- habits on the proliferating numbers of books which use the silly
- little construct, and arguing, in spite of the fact that they
- don't know what they're talking about, that since their books use
- it it must be okay, and suggesting that the pedants on
- comp.lang.c must not know what *they're* talking about -- now,
- that question has definitely shifted its focus, as evidenced by
- its three follow-on questions.
-
- > The issue that
- > a void function may not be compatible with a call to an int function
- > doesn't seem that significant, since nobody in their right mind would
- > design a compiler that way.
-
- Saying that "nobody in their right mind would design a compiler
- that way" is a pretty weak argument. Saying that "the C Standard
- allows a compiler to be designed that way," with the inference
- that portable code ought therefore to allow for the possibility,
- is a much stronger argument.
-
- > There is something magical about the old-style C that attracts me. I
- > can't quite put my finger on it... Can someone else identify with me? :)
-
- Well, I certainly prefer K&R C to ANSI C; I have no use for
- function prototypes (or for void functions, for that matter).
- But ANSI/ISO C is unquestionably modern practice; it's what I
- teach in my classes; it's what I've tried to migrate the FAQ list
- to concentrate on; it's what we mostly talk about here; it's what
- most C programmers should be programming in.
-
- Steve Summit
- scs@eskimo.com
-
- February 8, 1996: A dark day for the net
-